package com.gudaichaoren.spider.exception;

import com.gudaichaoren.spider.constant.Constants;
import com.gudaichaoren.spider.constant.IResponseStatus;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.UUID;

/**
 * 业务异常类
 * @author 188****7252
 * @date 2019/12/14 14:04
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class BusinessException extends RuntimeException{

    // 异常代码
    private Integer code;

    // 异常信息
    private String message;

    // 异常id
    private String errorId;

    // 异常数据
    private Object errorData;

    private BusinessException(Integer code, String message, Object errorData) {
        super(message);
        this.code = code;
        this.message = message;
        this.errorId = UUID.randomUUID().toString();
        this.errorData = errorData;
    }

    public BusinessException(String message) {
        this(Constants.Response.FAILURE.getCode(), message, null);
    }

    public BusinessException(IResponseStatus status) {
        this(status, null);
    }

    public BusinessException(IResponseStatus status, Object errorData) {
        this(status.getCode(), status.getMessage(), errorData);
    }
}